<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class QueryExplain</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name">Class QueryExplain</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
															<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
					</div>
	<div class="info-box-body">
        		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">class QueryExplain  rough utility class to get query explain plan and extract table names from  abitrary sql so we can run show create table on them.</p>
<p class="description"><p>This class needs a user defined method to find the database connection info  from the query and a bit of other data stored with the query_review_history table</p><p>The class is used as follows:</p><p>$result = $mysqli-&gt;query(&quot;SELECT sample, hostname_max, database_max FROM query_review_history WHERE checksum=1&quot;);  $row = $result-&gt;fetch_assoc();</p><p>$explainer = new QueryExplain($callback, $row);  print $explainer-&gt;explain();</p><p>where $callback might look like:  $callback = function(array $sample)  {       return array(           'host'  =&gt; $sample['hostname_max'],           'db'    =&gt; $sample['database_max'],           'user'  =&gt; 'username',           'password' =&gt; 'password',       );  }</p><p>The callback funtion will always take one array argument, and it needs to return  and array with the following keys defined: host,db,user,password; and optionally: port</p><p>Because the object takes data associated with one query to return the db connection  info, that means a QueryExplain object will always only be valid for one query,  and will maintain its own connection</p><p>Sharing connection objects would be advantageous if you want to explain many queries  which could be from the same database; but that's not needed for it's current use case.</p></p>
	<ul class="tags">
				<li><span class="field">author:</span> Gavin Towey &lt;<a href="mailto:gavin@box.com">gavin@box.com</a>&gt;</li>
			</ul>
		<p class="notes">
			Located in <a class="field" href="_QueryExplain.php.html">/QueryExplain.php</a> (line <span class="field">48</span>)
		</p>
		
				
		<pre></pre>
	
			</div>
</div>




	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
												<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
																																																				
												<div class="method-definition">
											<span class="method-result">QueryExplain</span>
										<a href="#__construct" title="details" class="method-name">__construct</a>
											(<span class="var-type">callback</span>&nbsp;<span class="var-name">$get_connection_func</span>, <span class="var-type">array</span>&nbsp;<span class="var-name">$sample</span>)
									</div>
																<div class="method-definition">
											<span class="method-result">null|string</span>
										<a href="#explain" title="details" class="method-name">explain</a>
										()
									</div>
																<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_create" title="details" class="method-name">get_create</a>
										()
									</div>
																<div class="method-definition">
											<span class="method-result">array</span>
										<a href="#get_tables_from_query" title="details" class="method-name">get_tables_from_query</a>
										()
									</div>
																<div class="method-definition">
											<span class="method-result">null</span>
										<a href="#get_table_status" title="details" class="method-name">get_table_status</a>
										()
									</div>
																<div class="method-definition">
											<span class="method-result">{string}</span>
										<a href="#result_as_table" title="details" class="method-name">result_as_table</a>
											(<span class="var-type">{MySQLi_Result}</span>&nbsp;<span class="var-name">$result</span>)
									</div>
								</div>
		</div>
	</div>		

	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
																<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>

<a name="method__construct" id="__construct"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">Constructor __construct</span> (line <span class="line-number">65</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Constructor.  See class documentation for explaination of the parameters</p>
	<ul class="tags">
				<li><span class="field">throws:</span> Exception  if a database connection cannot be made</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">QueryExplain</span>
		<span class="method-name">
			__construct
		</span>
					(<span class="var-type">callback</span>&nbsp;<span class="var-name">$get_connection_func</span>, <span class="var-type">array</span>&nbsp;<span class="var-name">$sample</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">callback</span>
				<span class="var-name">$get_connection_func</span><span class="var-description">: The callback function</span>			</li>
					<li>
				<span class="var-type">array</span>
				<span class="var-name">$sample</span><span class="var-description">: array of information about the query</span>			</li>
				</ul>
		
			
	</div>
<a name="methodexplain" id="explain"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">explain</span> (line <span class="line-number">144</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">If the given query is a SELECT statement, return the explain plan</p>
	<ul class="tags">
				<li><span class="field">return:</span> The explain plan, or an error message</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">null|string</span>
		<span class="method-name">
			explain
		</span>
				()
			</div>
	
		
			
	</div>
<a name="methodget_create" id="get_create"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_create</span> (line <span class="line-number">91</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Extract the table names from a query, and return the result of  SHOW CREATE TABLE tablename;</p>
	<ul class="tags">
				<li><span class="field">return:</span> the create table statements, or an error message</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_create
		</span>
				()
			</div>
	
		
			
	</div>
<a name="methodget_tables_from_query" id="get_tables_from_query"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get_tables_from_query</span> (line <span class="line-number">80</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Try to parse the real table names out of a sql query</p>
	<ul class="tags">
				<li><span class="field">return:</span> the list of tables in the query</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">array</span>
		<span class="method-name">
			get_tables_from_query
		</span>
				()
			</div>
	
		
			
	</div>
<a name="methodget_table_status" id="get_table_status"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_table_status</span> (line <span class="line-number">118</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Extract the table names and the return the result of  SHOW TABLE STATUS LIKE 'tablename' for each table;</p>
	<ul class="tags">
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">null</span>
		<span class="method-name">
			get_table_status
		</span>
				()
			</div>
	
		
			
	</div>
<a name="methodresult_as_table" id="result_as_table"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">result_as_table</span> (line <span class="line-number">216</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">given a mysqli result handle, format a string to look like the mysql cli</p>
<p class="description"><p>type tables</p></p>
	<ul class="tags">
				<li><span class="field">return:</span> The formatted result set string</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">{string}</span>
		<span class="method-name">
			result_as_table
		</span>
					(<span class="var-type">{MySQLi_Result}</span>&nbsp;<span class="var-name">$result</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">{MySQLi_Result}</span>
				<span class="var-name">$result</span><span class="var-description">: The result set handle</span>			</li>
				</ul>
		
			
	</div>
						
		</div>
	</div>


	<p class="notes" id="credit">
		Documentation generated on Mon, 12 Mar 2012 11:50:14 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.4</a>
	</p>
	</div></body>
</html>